<% layout('/layout/default.html', {title: '文件管理', libs: ['layui']}){ %>
<div class="main-content">
	<div class="card-header">
		<i class="fa fa-sitemap"></i> 文件管理
		<div class="header-tools float-right">
			<a href="#" class="btn btn-default btn-sm" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
			<% if(hasPermi('file:sysFile:edit')){ %>
			<a href="#" onclick="checkBeforeUpload()" class="btn btn-default btn-sm" title="上传文件"><i class="fa fa-plus"></i>上传文件</a>
			<% } %>
		</div>
	</div>
	<div class="container-fluid">
		<form id="searchForm" action="${ctx}/file/sysFile/listData" class="form-inline d-none">
			<div class="form-group">
				<label class="control-label">文件名称：</label>
				<div class="control-inline">
					<input name="name" maxlength="64" class="form-control form-control-sm"/>
					<input name="fileTreeId" id="fileTreeId" type="hidden"/>
				</div>
			</div>
			<div class="form-group">
				<button type="submit" class="btn btn-success btn-sm ">查询</button>
				<button id="reset" type="reset" class="btn btn-default btn-sm">重置</button>
			</div>
		</form>
		<table id="btGrid"></table>
	</div>
</div>
<% } %>
<script>
	// 初始化layui-table对象
	$('#btGrid').BTGrid({
		searchForm: $("#searchForm"),
		columnModel: [
			{title:'文件夹名称', field:'fileTreeName'},
			{title:'文件名称', field:'name', templet: function(row) {
				return '<div id="a" style="width:100px;overflow: hidden;text-overflow: ellipsis;">'+row.name +'</div>';
			} },
			{title:'文件大小', field:'fileSize'},
			{title:'文件路径', field:'path', templet: function(row) {
				return '<div style="width:100px;overflow: hidden;text-overflow: ellipsis;">'+row.path +'</div>';
			} },
			{title:'上传时间', field:'createDate',templet: function (row) {
				if (row.createDate){   // data不为空进行转换
					return (new Date(row.createDate)).Format("yyyy-MM-dd hh:mm:ss");
				} else {
					return ''; //data为空时不转换
				}
			}},
			{title:'操作', templet: function(row){
				var actions = [];
				<% if(hasPermi('file:sysFile:edit')){ %>
					actions.push('<a href="${ctx}/file/sysFile/download?id='+row.id+'" class="btn btn-xs btn-info" title="下载"><i class="fa fa-download"></i></a>&nbsp;&nbsp;');
					actions.push('<a href="${ctx}/file/sysFile/delete?id='+row.id+'" class="btn btn-xs btn-danger btnList" title="删除" data-confirm="确认要删除该文件吗?"><i class="far fa-trash-alt"></i></a>&nbsp;&nbsp;');
					actions.push('<a href="/file/sysFile/move?id='+row.id+'" class="btn btn-xs btn-info btnList" title="移动文件"><i class="fas fa-share"></i></a>&nbsp;');
				<% } %>
				return actions.join('');
			}}
		],
		// 加载成功后执行事件
		ajaxSuccess: function(data){
			
		}
	});
	
	function checkBeforeUpload(obj){
		js.layer.open({
			  type: 2,
			  area: ['20%', '65%'],
			  fixed: true, //不固定
			  maxmin: true,
			  title:'选择上传文件夹',
			  content: ['${ctx}/file/sysFile/fileTreeSelect','auto'],
			  btn: ['确认','取消'],
			  yes: function(index, layero){
				  var fileTreeId = $(layero).find("iframe")[0].contentWindow.backData();
				  if(fileTreeId!=""){
					  js.layer.close(index);
					  parent.layer.open({
						  type: 2,
						  area: ['65%', '50%'],
						  fixed: true, //不固定
						  maxmin: true,
						  title:'文件上传',
						  content: ['${ctx}/file/sysFile/uploadFile?fileTreeId='+fileTreeId,'auto'],
						  end:function(){
							  $('#btGrid').DataTable().ajax.reload();
						  }
						});
				  }else{
					  js.showMessage("未选择文件夹，请选择上传的文件夹");
				  }
			  }
		});
	}
</script>
